//获取上次保存的测算结果,点击保存按钮才会有效
function getLastResult(){
	var dateFrom = $("#"+tabId+" #sdate").val();
	var dateTo = $("#"+tabId+" #edate").val();
	planYear = $('#'+tabId+' #planYear').val() ;
	$("#editHosp_btn").click(function(){
		$(".editClass").each(function(i, n){
			var value = $(n).html();
			if(value && value!=""){
				if($(n).find("input").size()<=0){
					$(n).html('<input value="'+value+'"/>');
				}
			}
		})
	})
	$("#saveHosp_btn").unbind("click");
	$("#saveHosp_btn").bind("click", function(){
		var str = "";
		str += "hosp|";
		$(".editClass").each(function(i, n){
			if($(n).find("input").size()>0){
				var value = $(n).find("input").val();
				$(n).html(value);
				var valuely = $(n).parent().parent().find("tr:eq(3)").find("td:eq(0)").html();
				if($(n).parent().parent().attr("id")=="hospAvgDays"){
					$(n).parent().parent().find("tr:eq(2)").find("td").eq(0).html(Math.abs(parseFloat(value)-parseFloat(valuely)).toFixed(2));
				}else{
					var percent = "--";
					if(parseFloat(valuely)>0){
						percent = Math.abs((parseFloat(value)-parseFloat(valuely))/parseFloat(valuely)*100).toFixed(2)+"%";
					}
					$(n).parent().parent().find("tr:eq(2)").find("td").eq(0).html(percent);
				}
				
				if(parseFloat(value)>=parseFloat(valuely)){
					$(n).parent().parent().find("tr:eq(1)").find("td:eq(1)").html('<span style="color:red;font-size:8px;"><i class="glyphicon glyphicon-arrow-up"></i>');
				}else{
					$(n).parent().parent().find("tr:eq(1)").find("td:eq(1)").html('<span style="color:green;font-size:8px;"><i class="glyphicon glyphicon-arrow-down"></i>');
				}
			}
			if(i==0){
				str += "AvgDays:"+$(n).html()+",";
			}else if(i==1){
				str += "AvgFee:"+$(n).html()+",";
			}else if(i==2){
				str += "HCAvgFee:"+$(n).html()+",";
			}else if(i==3){
				str += "DrugFee:"+$(n).html()+",";
			}else if(i==4){
				str += "HCDrugFee:"+$(n).html()+",";
			}else if(i==5){
				str += "TotalCaseCnt:"+$(n).html()+",";
			}else if(i==6){
				str += "HCCaseCnt:"+$(n).html()+",";
			}else if(i==7){
				str += "HCTotalFund:"+$(n).html()+",";
			}else if(i==8){
				str += "TimeEff:"+$(n).html()+",";
			}else if(i==9){
				str += "FeeEff:"+$(n).html()+",";
			}else if(i==10){
				str += "DrugMateFee:"+$(n).html()+",";
			}else if(i==11){
				str += "HCDrugMateFee:"+$(n).html()+",";
			}
		})
		str = str.substr(0, str.length-1)
		$.post(contextPath + "/ForeCast/saveExpected.dhc", {quotaStr: str, saveType: "I",type:"hosp",roleName:qouta_roles,planYear:$('#'+tabId+' #planYear').val(),dateFrom:dateFrom,dateTo:dateTo}).done(function(result){
			if(result.success){
				drgUI.success("成功保存预测结果") ;
				drgUI.confirm({
					content : '是否保存为绩效标杆',
					callSure : function() {
						$("#"+tabId+" #saveHosp_manager_btn").click() ;
					}
				})
			}
		});
	})
	
	$("#"+tabId+" #saveDepGroup_btn").unbind("click");
	$("#"+tabId+" #saveDepGroup_btn").bind("click", function(){
		$("#resultDepGroup-table tbody").find("tr").each(function(i, n){
			var str = "";
			var depGroupCode=$(n).find("td").eq(2).find("input").attr("id")?$(n).find("td").eq(2).find("input").attr("id").split("_")[0]:"";
			str += depGroupCode+"|";
			if(qouta_roles=="医政"){
				var avgDays = $(n).find("td").eq(1).find("input").val();
				str += "AvgDays:"+avgDays+",";
				var avgFee = $(n).find("td").eq(2).find("input").val();
				str += "AvgFee:"+avgFee+",";
				var drugFee = $(n).find("td").eq(3).find("input").val();
				str += "DrugFee:"+drugFee+",";
				var totalCaseCnt = $(n).find("td").eq(4).find("input").val();
				str += "TotalCaseCnt:"+totalCaseCnt+",";
				var timeEff = $(n).find("td").eq(5).find("input").val();
				str += "TimeEff:"+timeEff+",";
				var feeEff = $(n).find("td").eq(6).find("input").val();
				str += "FeeEff:"+feeEff+",";
				var drugMateFee = $(n).find("td").eq(7).find("input").val();
				str += "DrugMateFee:"+drugMateFee+",";
			}else{
				var avgDays = $(n).find("td").eq(1).find("input").val();
				str += "AvgDays:"+avgDays+",";
				var avgFee = $(n).find("td").eq(2).find("input").val();
				str += "AvgFee:"+avgFee+",";
				var hcAvgFee = $(n).find("td").eq(3).find("input").val();
				str += "HCAvgFee:"+hcAvgFee+",";
				var drugFee = $(n).find("td").eq(4).find("input").val();
				str += "DrugFee:"+drugFee+",";
				var hcDrugFee = $(n).find("td").eq(5).find("input").val();
				str += "HCDrugFee:"+hcDrugFee+",";
				var totalCaseCnt = $(n).find("td").eq(6).find("input").val();
				str += "TotalCaseCnt:"+totalCaseCnt+",";
				var hcCaseCnt = $(n).find("td").eq(7).find("input").val();
				str += "HCCaseCnt:"+hcCaseCnt+",";
				var hcTotalFund = $(n).find("td").eq(9).find("input").val();
				str += "HCTotalFund:"+hcTotalFund+",";
				var timeEff = $(n).find("td").eq(10).find("input").val();
				str += "TimeEff:"+timeEff+",";
				var feeEff = $(n).find("td").eq(11).find("input").val();
				str += "FeeEff:"+feeEff+",";
				var drugMateFee = $(n).find("td").eq(12).find("input").val();
				str += "DrugMateFee:"+drugMateFee+",";
				var hcDrugMateFee = $(n).find("td").eq(13).find("input").val();
				str += "HCDrugMateFee:"+hcDrugMateFee+",";
			}
			str = str.substr(0, str.length-1)
			$.post(contextPath + "/ForeCast/saveExpected.dhc", {quotaStr: str, saveType: "I",type:"depGroup",roleName:qouta_roles,planYear:$('#'+tabId+' #planYear').val(),dateFrom:dateFrom,dateTo:dateTo}).done(function(result){
				if(!result.success){
					drgUI.warning(depGroupCode+":"+result.errorMessage) ;
					return false;
				}
				drgUI.success("成功保存预测结果") ;
			});
		})
		drgUI.confirm({
			content : '是否保存为绩效标杆',
			callSure : function() {
				$("#"+tabId+" #saveDepGroup_manager_btn").click() ;
			}
		})
	});
	
	$("#"+tabId+" #saveDep_btn").unbind("click");
	$("#"+tabId+" #saveDep_btn").bind("click", function(){
		$("#resultDep-table tbody").find("tr").each(function(i, n){
			var str = "";
			var depCode=$(n).find("td").eq(2).find("input").attr("id")?$(n).find("td").eq(2).find("input").attr("id").split("_")[0]:"";
			str += depCode+"|";
			if(qouta_roles=="医政"){
				var avgDays = $(n).find("td").eq(1).find("input").val();
				str += "AvgDays:"+avgDays+",";
				var avgFee = $(n).find("td").eq(2).find("input").val();
				str += "AvgFee:"+avgFee+",";
				var drugFee = $(n).find("td").eq(3).find("input").val();
				str += "DrugFee:"+drugFee+",";
				var totalCaseCnt = $(n).find("td").eq(4).find("input").val();
				str += "TotalCaseCnt:"+totalCaseCnt+",";
				var timeEff = $(n).find("td").eq(5).find("input").val();
				str += "TimeEff:"+timeEff+",";
				var feeEff = $(n).find("td").eq(6).find("input").val();
				str += "FeeEff:"+feeEff+",";
				var drugMateFee = $(n).find("td").eq(7).find("input").val();
				str += "DrugMateFee:"+drugMateFee+",";
			}else{
				var avgDays = $(n).find("td").eq(1).find("input").val();
				str += "AvgDays:"+avgDays+",";
				var avgFee = $(n).find("td").eq(2).find("input").val();
				str += "AvgFee:"+avgFee+",";
				var hcAvgFee = $(n).find("td").eq(3).find("input").val();
				str += "HCAvgFee:"+hcAvgFee+",";
				var drugFee = $(n).find("td").eq(4).find("input").val();
				str += "DrugFee:"+drugFee+",";
				var hcDrugFee = $(n).find("td").eq(5).find("input").val();
				str += "HCDrugFee:"+hcDrugFee+",";
				var totalCaseCnt = $(n).find("td").eq(6).find("input").val();
				str += "TotalCaseCnt:"+totalCaseCnt+",";
				var hcCaseCnt = $(n).find("td").eq(7).find("input").val();
				str += "HCCaseCnt:"+hcCaseCnt+",";
				var hcTotalFund = $(n).find("td").eq(9).find("input").val();
				str += "HCTotalFund:"+hcTotalFund+",";
				var timeEff = $(n).find("td").eq(10).find("input").val();
				str += "TimeEff:"+timeEff+",";
				var feeEff = $(n).find("td").eq(11).find("input").val();
				str += "FeeEff:"+feeEff+",";
				var drugMateFee = $(n).find("td").eq(12).find("input").val();
				str += "DrugMateFee:"+drugMateFee+",";
				var hcDrugMateFee = $(n).find("td").eq(13).find("input").val();
				str += "HCDrugMateFee:"+hcDrugMateFee+",";
			}
			str = str.substr(0, str.length-1)
			$.post(contextPath + "/ForeCast/saveExpected.dhc", {quotaStr: str, saveType: "I",type:"dep",roleName:qouta_roles,planYear:$('#'+tabId+' #planYear').val(),dateFrom:dateFrom,dateTo:dateTo}).done(function(result){
				if(!result.success){
					drgUI.warning(depCode+":"+result.errorMessage) ;
					return false;
				}
				drgUI.success("成功保存预测结果") ;
			});
		})
		drgUI.confirm({
			content : '是否保存为绩效标杆',
			callSure : function() {
				$("#"+tabId+" #saveDep_manager_btn").click() ;
			}
		})
	});
	
	$("#"+tabId+" #saveMDC_btn").unbind("click");
	$("#"+tabId+" #saveMDC_btn").bind("click", function(){
		$("#resultMDC-table tbody").find("tr").each(function(i, n){
			var str = "";
			var mdcCode=$(n).find("td").eq(2).find("input").attr("id")?$(n).find("td").eq(2).find("input").attr("id").split("_")[0]:"";
			str += mdcCode+"|";
			var avgDays = $(n).find("td").eq(1).find("input").val();
			str += "AvgDays:"+avgDays+",";
			var avgFee = $(n).find("td").eq(2).find("input").val();
			str += "AvgFee:"+avgFee+",";
			var hcAvgFee = $(n).find("td").eq(3).find("input").val();
			str += "HCAvgFee:"+hcAvgFee+",";
			var drugFee = $(n).find("td").eq(4).find("input").val();
			str += "DrugFee:"+drugFee+",";
			var hcDrugFee = $(n).find("td").eq(5).find("input").val();
			str += "HCDrugFee:"+hcDrugFee+",";
			var totalCaseCnt = $(n).find("td").eq(6).find("input").val();
			str += "TotalCaseCnt:"+totalCaseCnt+",";
			var hcCaseCnt = $(n).find("td").eq(7).find("input").val();
			str += "HCCaseCnt:"+hcCaseCnt+",";
			var hcTotalFund = $(n).find("td").eq(9).find("input").val();
			str += "HCTotalFund:"+hcTotalFund+",";
			var timeEff = $(n).find("td").eq(10).find("input").val();
			str += "TimeEff:"+timeEff+",";
			var feeEff = $(n).find("td").eq(11).find("input").val();
			str += "FeeEff:"+feeEff+",";
			str = str.substr(0, str.length-1)
			$.post(contextPath + "/ForeCast/saveExpected.dhc", {type2: str, parmdcCode: mdcCode, type1: "I",planYear:$('#'+tabId+' #planYear').val()}).done(function(result){
				if(!result.success){
					drgUI.warning(mdcCode+":"+result.errorMessage) ;
					return false;
				}
				drgUI.success("保存完毕") ;
			});
		})
	});
	
	$("#"+tabId+" #saveADRG_btn").unbind("click")
	$("#"+tabId+" #saveADRG_btn").bind("click", function(){
		$("#resultADRG-table tbody").find("tr").each(function(i, n){
			var str = "";
			var adrgCode=$(n).find("td").eq(2).find("input").attr("id")?$(n).find("td").eq(2).find("input").attr("id").split("_")[0]:"";
			str += adrgCode+"|";
			var avgDays = $(n).find("td").eq(1).find("input").val();
			str += "AvgDays:"+avgDays+",";
			var avgFee = $(n).find("td").eq(2).find("input").val();
			str += "AvgFee:"+avgFee+",";
			var hcAvgFee = $(n).find("td").eq(3).find("input").val();
			str += "HCAvgFee:"+hcAvgFee+",";
			var drugFee = $(n).find("td").eq(4).find("input").val();
			str += "DrugFee:"+drugFee+",";
			var hcDrugFee = $(n).find("td").eq(5).find("input").val();
			str += "HCDrugFee:"+hcDrugFee+",";
			var totalCaseCnt = $(n).find("td").eq(6).find("input").val();
			str += "TotalCaseCnt:"+totalCaseCnt+",";
			var hcCaseCnt = $(n).find("td").eq(7).find("input").val();
			str += "HCCaseCnt:"+hcCaseCnt+",";
			var hcTotalFund = $(n).find("td").eq(9).find("input").val();
			str += "HCTotalFund:"+hcTotalFund+",";
			var timeEff = $(n).find("td").eq(10).find("input").val();
			str += "TimeEff:"+timeEff+",";
			var feeEff = $(n).find("td").eq(11).find("input").val();
			str += "FeeEff:"+feeEff+",";
			str = str.substr(0, str.length-1)
			$.post(contextPath + "/ForeCast/saveExpected.dhc", {type2: str, paradrgCode: adrgCode, type1: "I"}).done(function(result){
				if(!result.success){
					drgUI.warning(adrgCode+":"+result.errorMessage) ;
					return false;
				}
				drgUI.success("保存完毕") ;
			});
		})
	});
	
	$("#"+tabId+" #saveDRGs_btn").unbind("click");
	$("#"+tabId+" #saveDRGs_btn").bind("click", function(){
		$("#resultDRGs-table tbody").find("tr").each(function(i, n){
			var str = "";
			var drgsCode=$(n).find("td").eq(2).find("input").attr("id")?$(n).find("td").eq(2).find("input").attr("id").split("_")[0]:"";
			str += drgsCode+"|";
			var avgDays = $(n).find("td").eq(1).find("input").val();
			str += "AvgDays:"+avgDays+",";
			var avgFee = $(n).find("td").eq(2).find("input").val();
			str += "AvgFee:"+avgFee+",";
			var hcAvgFee = $(n).find("td").eq(3).find("input").val();
			str += "HCAvgFee:"+hcAvgFee+",";
			var drugFee = $(n).find("td").eq(4).find("input").val();
			str += "DrugFee:"+drugFee+",";
			var hcDrugFee = $(n).find("td").eq(5).find("input").val();
			str += "HCDrugFee:"+hcDrugFee+",";
			var totalCaseCnt = $(n).find("td").eq(6).find("input").val();
			str += "TotalCaseCnt:"+totalCaseCnt+",";
			var hcCaseCnt = $(n).find("td").eq(7).find("input").val();
			str += "HCCaseCnt:"+hcCaseCnt+",";
			var hcTotalFund = $(n).find("td").eq(9).find("input").val();
			str += "HCTotalFund:"+hcTotalFund+",";
			var timeEff = $(n).find("td").eq(10).find("input").val();
			str += "TimeEff:"+timeEff+",";
			var feeEff = $(n).find("td").eq(11).find("input").val();
			str += "FeeEff:"+feeEff+",";
			str = str.substr(0, str.length-1)
			$.post(contextPath + "/ForeCast/saveExpected.dhc", {type2: str, pardrgCode: drgsCode, type1: "I"}).done(function(result){
				if(!result.success){
					drgUI.warning(drgsCode+":"+result.errorMessage) ;
					return false;
				}
				drgUI.success("保存完毕") ;
			});
		})
	});
	
	$.post(contextPath+"/ForeCast/getLastResultHosp.dhc", 
			{saveType: "I",
		     stdYear:planYear,
		     dateFrom:dateFrom,
		     dateTo:dateTo
		     
			})
	.done(function(result){
		var data = result.data;
		if(data){
			loadResultTableHosp(data);
		}
	});
	$.post(contextPath+"/ForeCast/getLastResultDepGroup.dhc", 
			{saveType: "I",
		     stdYear:planYear,
		     dateFrom:dateFrom,
		     dateTo:dateTo
		   
			})
	.done(function(result){
		var data = result.data;
		if(data){
			loadResultTableDepGroup(data);
		}
	});
	
	//获取科室上次预测的数据
	$.post(contextPath+"/ForeCast/getLastResultDep.dhc", {
		saveType: "I",
		stdYear:planYear,
	     dateFrom:dateFrom,
	     dateTo:dateTo	
	})
	.done(function(result){
		var data = result.data;
		if(data){
			loadResultTableDep(data);
		}
	});
	
//	//获取MDC上次预测的数据
//	$.post(contextPath+"/ForeCast/getLastResultMDC.dhc", {dateFrom:dateFrom, dateTo:dateTo, type1: "I"})
//	.done(function(result){
//		var data = result.data;
//		if(data){
//			loadResultTableMDC(data);
//		}
//	});
//	
//	//获取ADRG上次预测的数据
//	$.post(contextPath+"/ForeCast/getLastResultADRG.dhc", {dateFrom:dateFrom, dateTo:dateTo, type1: "I"})
//	.done(function(result){
//		var data = result.data;
//		if(data){
//			loadResultTableAdrg(data);
//		}
//	});
//	
//	//获取ADRG上次预测的数据
//	$.post(contextPath+"/ForeCast/getLastResultDRG.dhc", {dateFrom:dateFrom, dateTo:dateTo, type1: "I"})
//	.done(function(result){
//		var data = result.data;
//		if(data){
//			loadResultTableDrgs(data);
//		}
//	});
	
	
}